import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { OrderQueryService } from 'src/app/service/me/order-query.service';

@Component({
  selector: 'app-order-progress',
  templateUrl: './order-progress.component.html',
  styleUrls: ['./order-progress.component.scss']
})
export class OrderProgressComponent implements OnInit {
  state = [
    { key: 'sourceTime', title: '已申请' },
    { key: 'pendingDateTime', title: '待受理' },
    { key: 'processingDateTime', title: '已受理' },
    { key: 'evaluatingDateTime', title: '待评价' },
    { key: 'solvedDateTime', title: '已完成' },
    { key: 'backDateTime', title: '退回' },
  ]
  constructor(
    private orderQuery: OrderQueryService,
    private route: ActivatedRoute
  ) { }

  data: any = []

  ngOnInit(): void {
    this.route.queryParams.subscribe(res => {

      this.getOrderProgress(res['funcNo'])
    })
  }

  getOrderProgress(funcNo: string){
    this.orderQuery._getOrderProgress(funcNo).subscribe({
      next: (res) => {
        console.log(res)
        if(res){
          this.state.forEach(item => {
            if(res[item.key]){
              this.data.push({ title: item.title, date: res[item.key] })
            }
          })
        }
        console.log(this.data)
      },
      error: (error) => {
      }
    })
  }

}
